const multer  = require('multer')
const path = require('path');
const storage = multer.diskStorage({
  // 自定义文件上传的目录
  destination: function (req, file, cb) {
    cb(null, './public/uploads')
  },
  // 自定义文件上传的名字
  filename: function (req, file, cb) {
 
    const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9)
    cb(null, file.fieldname + '-' + uniqueSuffix + path.extname(file.originalname))
  }
})
const upload = multer({ storage: storage })

module.exports = upload